package be.scond.cartpool.model;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;


@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Order {

    @PrimaryKey 
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
	
	@Persistent
	private ShoppingList shoppingList;

	@Persistent
	private Key userKey;
	
	@Persistent
	private String userName; 
	
	@Persistent
	private String product;
	
	@Persistent
	private String description;
	
	@Persistent
	private int quantity; 
	
	@Persistent
	private BigDecimal price;
	
	public Order(){}
	
	public String toXmlString(){
		String str = "";
		str += "<order>";
		str += "<key>"+KeyFactory.keyToString(key)+"</key>";
		str += "<userName>"+userName+"</userName>";
		str += "<product>"+product+"</product>";
		str += "<description>"+description+"</description>";
		str += "<quantity>"+quantity+"</quantity>";
		NumberFormat form = new DecimalFormat("####0.00");
		str += "<price>"+form.format(price)+"</price>";
		str += "</order>";
		return str;
	}
	
	public Key getKey() {
		return key;
	}
	public void setKey(Key key) {
		this.key = key;
	}

	public ShoppingList getShoppingList() {
		return shoppingList;
	}
	public void setShoppingList(ShoppingList shoppingList) {
		this.shoppingList = shoppingList;
	}
	
	public Key getUserKey() {
		return userKey;
	}
	public void setUserKey(Key userKey) {
		this.userKey = userKey;
	}

	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getProduct() {
		return product;
	}
	public void setProduct(String product) {
		this.product = product;
	}
	
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}

	public int getQuantity() {
		return quantity;
	}
	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}
	
	public BigDecimal getPrice() {
		return price;
	}
	public void setPrice(BigDecimal price) {
		this.price = price;
	}
}
